{% extends "base.html" %}
  {% block content %}
    {% from "forms/macros.html" import render_field_busqueda %}
     <SCRIPT LANGUAGE="JavaScript">
	
		url_1 = "/item/modificar/ID/"
		url_2 = "/item/eliminar/ID/"
		url_3 = "/item/consultar/ID/"
		url_4 = "/item/adjuntar/ID/"
		url_5 = "/calculo/individual/ID/"
		url_6 = "/item/revivir/ID/"
		url_7 = "/item/historial/ID/"
		url_8 = "/item/seleccionar/ID/"	
		url_9 = "/item/reporte_historial/ID/"
		
		id_href_1 = 'modificar'
		id_href_2 = 'eliminar'
		id_href_3 = 'consultar'
		id_href_4 = 'adjuntar'
		id_href_5 = 'impacto'
		id_href_6 = 'revivir'
		id_href_7 = 'historial'
		id_href_8 = 'seleccionar'
		id_href_9 = 'reporte_historial'
 
		function obtener_id(id) {
        	link_1 = document.getElementById(id_href_1)
        	link_2 = document.getElementById(id_href_2)
        	link_3 = document.getElementById(id_href_3)
        	link_4 = document.getElementById(id_href_4)
        	link_5 = document.getElementById(id_href_5)
        	link_6 = document.getElementById(id_href_6)
        	link_7 = document.getElementById(id_href_7)
        	link_8 = document.getElementById(id_href_8)
        	link_9 = document.getElementById(id_href_9)
        	
        	new_url_1 = url_1.replace('ID', id)
        	new_url_2 = url_2.replace('ID', id)
        	new_url_3 = url_3.replace('ID', id)
        	new_url_4 = url_4.replace('ID', id)
        	new_url_5 = url_5.replace('ID', id)
        	new_url_6 = url_6.replace('ID', id)
        	new_url_7 = url_7.replace('ID', id)
        	new_url_8 = url_8.replace('ID', id)
        	new_url_9 = url_9.replace('ID', id)
        	
        	link_1.href = new_url_1
        	link_2.href = new_url_2
        	link_3.href = new_url_3
        	link_4.href = new_url_4
        	link_5.href = new_url_5
        	link_6.href = new_url_6
        	link_7.href = new_url_7
        	link_8.href = new_url_8
        	link_9.href = new_url_9
		}
		
		function pregunta(){
    		if(confirm('Esta seguro de que desea eliminar el item?')){
    			return true;
    		}else{
    			return false;
    		}
    	}
   
    
    </SCRIPT>
    <h2> Administracion de Items </h2>
    <form method="POST" action={{ url_for('items.administracion_item') }} class="form">
   		{{ form.csrf_token }} 	
   <div style="overflow:auto; width: 770px; height: 550px;" > 
   	 <table " > 
     	 <tr >
     	 	 <th></th>
  			 <th>  <label>Filtros</label> </th>
     		 <th>{{ render_field_busqueda(form.nombre, class="input text") }}</th>
     		 <th>{{ render_field_busqueda(form.version, class="input text") }}</th>
     		 <th>{{ render_field_busqueda(form.prioridad, class="input text") }}</th>
     		 <th>{{ render_field_busqueda(form.costo, class="input text",readonly=true) }}</th>
     		 <th>{{ render_field_busqueda(form.complejidad, class="input text") }}</th>
     		 <th>{{ render_field_busqueda(form.duracion, class="input text") }}</th>
     		 <th>{{ render_field_busqueda(form.estado, class="input text") }}</th>
     		 <th>{{ render_field_busqueda(form.fecha_creacion, class="input text",readonly=true) }}</th>
     		 <th>{{ render_field_busqueda(form.numero, class="input text",readonly=true) }}</th> 
     		 <th>{{ render_field_busqueda(form.fase, class="input text") }}</th>   
     		
      	</tr >  			
  		<tr >
 			<th></th>
  			<th> <center>ID </center></th>
      		<th> <center> NOMBRE <c/enter></td>
      		<th> <center> VERSION <c/enter></td>
      		<th> <center> PRIORIDAD <c/enter></td>
      		<th> <center> COSTO <c/enter></td>
      		<th> <center> COMPLEJIDAD <c/enter></td>
      		<th> <center> DURACION <c/enter></td>
      		<th> <center> ESTADO <c/enter></td>
      		<th> <center> FECHA DE CREACION <c/enter></td>
      		<th> <center> POSICION <c/enter></td>
      		<th> <center> FASE <c/enter></td>
      		
      	</tr >  		
		{% for item in items %}			
   				<tr >
   				  <th><input type = "radio" name = "seleccionado" id="select" onchange="obtener_id({{item.id}})"></th>
      			  <td> <center>{{ item.id }} </center></td>      			  
      			  <td> <center>{{ item.nombre }} <center></td>
      			  <td> <center>{{ item.version }} <center></td>
      			  <td> <center>{{ item.prioridad }} <center></td>
      			  <td> <center>{{ item.costo}} <center></td>
      			  <td> <center>{{ item.complejidad }} <center></td>
      			  <td> <center>{{ item.duracion }} <center></td>
      			  <td> <center>{{ item.estado }} <center></td>
      			  <td> <center>{{ item.fecha_creacion }} <center></td>
      			  <td> <center>{{ item.numero}} <center></td>    		
      			  <td> <center>{{ item.fase.nombre }} <center></td>    			 
      			
   		</tr>  		 	
		{% endfor %}				
		
	</table> 
	</div> 
		 <div class="buttons">
                <button type="submit" class="button green">Buscar</button>
                <button type="submit" class="button green">
                		<a href="{{ url_for('items.seleccionar_fase') }}">Crear</a>
       			 </button>
       			 <button type="submit" class="button green">
               		 <a href="" id="modificar">Modificar</a>
        		</button>
        		<button type="submit" class="button green">
                		<a href="" id="consultar">Consultar</a>
        		</button>
        		<button type="submit" class="button green">
                		<a href="" id="adjuntar">Archivos</a>
        		</button>
        		<button type="submit"  onclick =  "return pregunta()">
        			<a href="" id="eliminar">Eliminar</a>
        		</button>
                <button type="submit" class="button green">
                		<a href="" id="impacto">Impacto</a>
        		</button>
        		<button type="submit" class="button green">
                		<a href="" id="revivir">Revivir</a>
        		</button>
        		<button type="submit" class="button green">
                		<a href="" id="seleccionar">Revertir</a>
        		</button>
        		
        		<button type="submit" class="button green">
                		<a href="" id="historial">Historial</a>
        		</button>	
        		
        		<button type="submit" class="button green">
                		<a href="{{ url_for('items.reporte_item') }}">Reporte</a>
        		</button>	
        		<button type="submit" class="button green">
                		<a href="" id="reporte_historial">Reporte Historial</a>
        		</button>		
        		
    	</div>  
   
    </form>    
  {% endblock %}